class Notifier < ActionMailer::Base

  # Subject can be set in your I18n file at config/locales/en.yml
  # with the following lookup:
  #
  #   en.notifier.activate_user.subject
  #
  def after_reg user, activate_url, root_url, site_email
    @user = user
    @activate_url = activate_url
    @root_url = root_url
    @site_email = site_email
    mail :to => @user.email, :from => site_email, :subject => I18n.t("letter.activation.subject")
  end

  def recover user, reset_url, root_url, site_email
    @user = user
    @reset_url = reset_url
    @root_url = root_url
    @site_email = site_email
    mail :to => @user.email, :from => site_email, :subject => I18n.t("letter.recover.subject")
  end

  def new_password user, root_url, site_email
    @user = user
    @root_url = root_url
    @site_email = site_email
    mail :to => @user.email, :from => site_email, :subject => I18n.t("letter.new_password.subject")
  end

  def for_operator edit_link, order, site_email
    operators = User.find(:all, :joins => :roles, :conditions => ["roles.name = 'operator'"])
    operator_emails = operators.map do |oper| oper.email end
    @edit_link = edit_link
    @order = order
    @user = @order.user
    @site_mail = site_email
    mail :to => operator_emails, :from => site_email, :subject => I18n.t("letter.for_operator.subject", :order_id => @order.id)
  end

  def for_user order, show_order_link, root_link, site_email
    @order = order
    @show_order_link = show_order_link
    @root_link = root_link
    @site_email = site_email
    mail :to => @order.user.email, :from => site_email, :subject => I18n.t("letter.for_user.subject", :order_id => @order.id)
  end
end
